package com.kingwood.algorithm.test;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: TODO
 * @Date: 2024/2/26 18:40
 * @Modified By：
 * @Version 1.0
 */
public class GetFloorAreaByFlag {
    /**
     * 从前有个村庄，村民们喜欢在各种田地上插上小旗子，旗子上标识了各种不同的数字。
     * 某天集体村民决定将覆盖相同数字的最小矩阵形的土地分配给村里做出巨大贡献的村民，请问此次分配土地，做出贡献的村民种最大会分配多大面积?
     */

    static class Rect {
        int minRow = Integer.MAX_VALUE;
        int maxRow = Integer.MIN_VALUE;
        int minCol = Integer.MAX_VALUE;
        int maxCol = Integer.MIN_VALUE;

        private void setRow(int row) {
            this.minRow = Math.min(this.minRow, row);
            this.maxRow = Math.max(this.maxRow, row);
        }

        private void setCol(int col) {
            this.minCol = Math.min(this.minCol, col);
            this.maxCol = Math.max(this.maxCol, col);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt(); // 长（行数）
        int n = scanner.nextInt(); // 宽（列数）

        HashMap<Integer, Rect> rects = new HashMap<Integer, Rect>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int num = scanner.nextInt();

                if (num > 0) {
                    rects.putIfAbsent(num, new Rect());
                    rects.get(num).setRow(i);
                    rects.get(num).setCol(j);
                }
            }
        }

        int maxArea = 0;
        for (int num : rects.keySet()) {
            Rect rect = rects.get(num);
            int rectArea = (rect.maxRow - rect.minRow + 1) * (rect.maxCol - rect.minCol + 1);
            maxArea = Math.max(maxArea, rectArea);
        }

        System.out.println(maxArea);
    }
}
